
package com.tools.cleanmaster.ui.view.trash;

import android.graphics.drawable.Drawable;

import com.tools.cleanmaster.model.item.TrashItem;
import com.tools.cleanmaster.utils.StringUtils;

/**
 * 所有item型TrashViewItem的基类
 * @author ouyang
 *
 */
public class TrashViewItemSingle implements TrashViewItem {

    public final TrashItem mTrashItem;
    final TrashGroup mGroup;

    TrashViewItemSingle(TrashItem item, TrashGroup group) {
        mTrashItem = item;
        mGroup = group;
    }

    TrashItem getTrashItem() {
        return mTrashItem;
    }

    @Override
    public int compareTo(TrashViewItem item) {
        if (item instanceof TrashViewItemSingle) {
            TrashViewItemSingle t = (TrashViewItemSingle) item;
            if (getTotalSize() > t.getTotalSize()) {
                return -1;
            } else if (getTotalSize() < t.getTotalSize()) {
                return 1;
            } else {
                return 0;
            }
        } else {
            return 1;
        }
    }

    @Override
    public String getStatus() {
        return StringUtils.getSizeString(getTotalSize());
    }

    @Override
    public boolean isChecked() {
        return mTrashItem.isSelected;
    }

    @Override
    public void onCheckedChanged(boolean isChecked, boolean callParent) {
        mTrashItem.isSelected = isChecked;
        mGroup.onChildCheckedChanged();
    }

    @Override
    public boolean isHalfChecked() {
        return false;
    }

    @Override
    public long getTotalSize() {
        return mTrashItem.size;
    }

    @Override
    public long getSelectedSize() {
        return isChecked() ? getTotalSize() : 0l;
    }

    @Override
    public Drawable getIcon() {
        return null;
    }

    @Override
    public String getTitle() {
        return mTrashItem.pkgName;
    }
}
